package com.jingdianjichi.subject.common.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.jingdianjichi.subject.common.enums.ResultCodeEnum;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;

/**
 * result 类
 *
 * @author 熊苏鹏1
 * @date 2025/1/30 23:17
 * @description 返回统一结果
 */
public class Result<T> {

    private  Boolean success;
    private int code;
    private String message;
    private T data;

    public Boolean getSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result<Void> ok(){
        Result<Void> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return result;
    }
    public static <T> Result<T> ok(T data){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }
    public static Result<Void> fail(){
        Result<Void> result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getMessage());
        return result;
    }
    public static <T> Result<T> fail(T message){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(message.toString());
        result.setData(null);
        return result;
    }
}
